// 弹窗工具类
/**
 * 加载框
 * @param {boolean} mask 是否显示透明蒙层，放置触摸穿透 
 */
const showLoading = (title='', mask = true) => {
    wx.showLoading({
        title: title,
        mask: mask,
    })
}
/**
 * 弹框
 * @param {string} title 弹框内容 
 * @param {string} icon  图标
 * @param {number} duration  持续时间
 */
const showToast = (title, icon = 'none', duration = 1500) => {
    wx.showToast({
        title: title,
        icon: icon,
        duration: duration
    })
}

/**
 * 失败弹窗
 * @param {string} title 弹框内容 
 * @param {number} duration  持续时间
 */
const showErrorToast = (title,duration = 1500) =>{
    showToast(title,"error",duration);
}

/**
 * 显示带删除的弹框
 * @param {*} func 
 */
const showModal = (func,title='提示',content='确认进行此操作？')=>{
    wx.showModal({
        title: title,
        content:content,
        success(res) {
            if (res.confirm) {
                if (func) {
                    func(res);
                }
            }
        }
    })
}

/**
 * 显示确认弹框
 * @param {*} func 
 */
const showConfirmModal = (func,content='确认进行此操作？')=>{
    wx.showModal({
        title: "提示",
        content:content,
        showCancel: false,
        success(res) {
            if (res.confirm) {
                if (func) {
                    func(res);
                }
            }
        }
    })
}

/**
 * 销毁加载状态
 */
const hideLoading = ()=>{
    wx.hideLoading();
}


module.exports = {
    showLoading,
    showToast,
    showErrorToast,
    showModal,
    hideLoading,
    showConfirmModal
}